/**
 * @Copyright 2012, Founder Mobile Media Technology（Chongqing） Co., Ltd L.P. All
 *            rights reserved. The information contained herein is confidential
 *            and proprietary to Founder Mobile Media Technology（Chongqing） Co.,
 *            Ltd, and considered a trade secret as defined under civil and
 *            criminal statutes. Founder Mobile Media Technology（Chongqing） Co.,
 *            Ltd shall pursue its civil and criminal remedies in the event of
 *            unauthorized use or misappropriation of its trade secrets. Use of
 *            this information by anyone other than authorized employees of
 *            Founder Mobile Media Technology（Chongqing） Co., Ltd is granted
 *            only under a written non-disclosure agreement, expressly
 *            prescribing the scope and manner of such use.
 */
package com.g2room.map;


/**
 * 
 *
 * @createTime: May 31, 2013 2:32:20 PM
 * @author: <a href="mailto:gaoxg@FOUNDER.COM.CN">Xuguo Gao</a>
 * @version: 0.1
 * @lastVersion: 0.1
 * @updateTime: 
 * @updateAuthor: <a href="mailto:gaoxg@FOUNDER.COM.CN">Xuguo Gao</a>
 * @changesSum: 
 * 
 */
public class LazyMap {


	/**
	 * 所谓LazyMap，意思就是这个Map中的键/值对一开始并不存在，当被调用到时才创建.
	 * 我们这样来理解：我们需要一个Map，但是由于创建成员的方法很“重”（比如数据库访问），
	 * 或者我们只有在调用get()时才知道如何创建，或者Map中出现的可能性很多很多， 我们无法在get()之前添加所有可能出现的键/值对，
	 * 我们觉得没有必要去初始化一个Map而又希望它可以在必要时自动处理数据
	 * 
	 */
	@SuppressWarnings(value = { "unchecked" })
	public static void demoLazyMap() {
//		System.out.println(StringUtils.center(" demoLazyMap ", 40, "="));
//		Factory factory = new Factory() {
//			public Object create() {
//				return new Date();
//			}
//		};
//		Map lazy = LazyMap.decorate(new HashMap(), factory);
//		System.out.println("map:" + lazy);// lazy为空
//		System.out.println(lazy.get("123"));
//		System.out.println(lazy.get("345"));
//		System.out.println(StringUtils.repeat("=", 40));
	}
}
